package com.ruoyi.mes.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.SecurityUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.PreAuthorize;
import com.ruoyi.mes.domain.MesProcessExec;
import com.ruoyi.mes.service.IMesProcessExecService;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 工艺施工Controller
 * 
 * @author ruoyi
 * @date 2021-12-03
 */
@RestController
@RequestMapping("/processExec")
public class MesProcessExecController extends BaseController
{
    @Autowired
    private IMesProcessExecService mesProcessExecService;

    /**
     * 查询工艺施工列表
     */
    @PreAuthorize(hasPermi = "mes:processExec:list")
    @GetMapping("/list")
    public TableDataInfo list(MesProcessExec mesProcessExec)
    {
        startPage();
        List<MesProcessExec> list = mesProcessExecService.selectMesProcessExecList(mesProcessExec);
        return getDataTable(list);
    }


    /**
     * 获取树
     */
    @GetMapping("/treeSelect")
    public AjaxResult treeSelect(MesProcessExec mesProcessExec)
    {
        List<MesProcessExec> list = mesProcessExecService.selectMesProcessExecList(mesProcessExec);
        return AjaxResult.success(mesProcessExecService.buildProcessExecTreeSelect(list));
    }

    /**
     * 导出工艺施工列表
     */
    @PreAuthorize(hasPermi = "mes:processExec:export")
    @Log(title = "工艺施工", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MesProcessExec mesProcessExec) throws IOException
    {
        List<MesProcessExec> list = mesProcessExecService.selectMesProcessExecList(mesProcessExec);
        ExcelUtil<MesProcessExec> util = new ExcelUtil<MesProcessExec>(MesProcessExec.class);
        util.exportExcel(response, list, "工艺施工数据");
    }

    /**
     * 获取工艺施工详细信息
     */
    @PreAuthorize(hasPermi = "mes:processExec:query")
    @GetMapping(value = "/{processExecUuid}")
    public AjaxResult getInfo(@PathVariable("processExecUuid") String processExecUuid)
    {
        return AjaxResult.success(mesProcessExecService.selectMesProcessExecByProcessExecUuid(processExecUuid));
    }

    /**
     * 生成工艺施工
     */
    @PreAuthorize(hasPermi = "mes:processExec:add")
    @Log(title = "工艺施工", businessType = BusinessType.INSERT)
    @PostMapping("/gen")
    public AjaxResult gen(@RequestBody MesProcessExec mesProcessExec)
    {
        int r = 0;
        mesProcessExec.setCreateBy(SecurityUtils.getUsername());
        mesProcessExecService.genProcessExec(mesProcessExec);
        if("success".equals(mesProcessExec.getResultMsg())){
            r=1;
        }
        return toAjax(r);
    }

    /**
     * 新增工艺施工
     */
    @PreAuthorize(hasPermi = "mes:processExec:add")
    @Log(title = "工艺施工", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MesProcessExec mesProcessExec)
    {
        return toAjax(mesProcessExecService.insertMesProcessExec(mesProcessExec));
    }

    /**
     * 修改工艺施工
     */
    @PreAuthorize(hasPermi = "mes:processExec:edit")
    @Log(title = "工艺施工", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MesProcessExec mesProcessExec)
    {
        return toAjax(mesProcessExecService.updateMesProcessExec(mesProcessExec));
    }

    /**
     * 删除工艺施工
     */
    @PreAuthorize(hasPermi = "mes:processExec:remove")
    @Log(title = "工艺施工", businessType = BusinessType.DELETE)
	@DeleteMapping("/{processExecUuids}")
    public AjaxResult remove(@PathVariable String[] processExecUuids)
    {
        return toAjax(mesProcessExecService.deleteMesProcessExecByProcessExecUuids(processExecUuids));
    }
}
